package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.IDishService;
import com.sky.service.ISetmealService;
import com.sky.vo.DishItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 微信 setmeal
 */
@RestController(value = "userSetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {
    @Autowired
    private ISetmealService setmealService;
    @Autowired
    private IDishService dishService;
    @Cacheable(value = "setmealCache",key = "#categoryId")
    @GetMapping("/list")
    public Result<List<Setmeal>> list(Long categoryId){
        List<Setmeal> setmealList=setmealService.list(categoryId);
        return Result.success(setmealList);
    }

    /**
     * 查询套餐包含的菜品
     * @param id
     * @return
     */
    @Cacheable(value = "setmealCache",key = "'套餐id'+#id")
    @GetMapping("/dish/{id}")
    public Result<List<DishItemVo>> getBySetmealId(@PathVariable Long id){
        List<DishItemVo> dishItemVos=dishService.getBySetmealId(id);
        return Result.success(dishItemVos);
    }
}
